package day01;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class MyComparator {
    public static void main(String[] args) {
        ArrayList<Order> list = new ArrayList<>();
        list.add(new Order("o001","sn001","g001","c001",2,9.9));
        list.add(new Order("o002","sn002","g002","c002",1,1400));
        list.add(new Order("o003","sn003","g003","c003",3,189));
        list.add(new Order("o005","sn005","g005","c005",1,2008));
        list.add(new Order("o004","sn004","g004","c004",54,800));
        list.add(new Order("o008","sn008","g008","c008",3,356));
        list.add(new Order("o007","sn007","g007","c007",8,19.9));
        list.add(new Order("o006","sn006","g006","c006",1,39.9));

        //本身就是可比较的 实现过compare接口
       /* ArrayList<String> list1 = new ArrayList<>();
        list1.add("1400");
        list1.add("1200");
        list1.add("360");
        list1.add("9");
        list1.add("2000");
        list1.add("198");

        Collections.sort(list1);

        for (String integer : list1) {
            System.out.println(integer);
        }*/

        //按照订单的金额进行升序排列
        Collections.sort(list);//如果想要比较两个东西，你得描述清楚，到底按照什么样的比较规则去比较，传一个比较器

        for (Order order : list) {
            System.out.println(order);
        }



    }

}


